﻿using System;
using System.Collections.Generic;

namespace Simp.CodeModel.CoreFunctions.Sequences
{
	/// <summary>Encapsulates a function computing the lenght of a sequence.</summary>
	public class LenFunction : IFunction
	{
		private static readonly string[] PARAMETER_NAMES = new[] { "sequence" };

		#region IFunction Members
		string IFunction.FunctionName
		{
			get { return "Len"; }
		}

		string[] IFunction.ParameterNames
		{
			get { return PARAMETER_NAMES; }
		}

		IFunctionParameterBinding[] IFunction.DefaultParameterValues
		{
			get { return FunctionHelper.EmptyBindings; }
		}

		IFunction IFunction.Simplify(SimplificationMode simplificationMode, params IFunction[] parameters)
		{
			FunctionHelper.ValidateParameters(this, parameters);

			ISequenceAccessor accessor = FunctionHelper.GetAccessor(parameters[0]);
			
			if (accessor == null)
			{
				return null;
			}
			else
			{
				return new IntegerFunction(accessor.Count);
			}
		}

		IFunction IFunction.AcceptVisitor(IFunctionVisitor visitor)
		{
			return null;
		}
		#endregion
	}
}